package io.gitee.mojingjiao.day05;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;


public class TestNum1 {
    @Test
    public void test(){
    String s = "Teach Yourself Programming in Ten Years\n" +
            "Researchers (Bloom (1985), Bryan & Harter (1899), Hayes (1989),\n" +
            "Simmon & Chase (1973)) have shown it takes about ten years to\n" +
            "develop expertise in any of a wide variety of areas, including\n" +
            "chess playing, music composition, telegraph operation, painting,\n" +
            "piano playing, swimming, tennis, and research in neuropsychology\n" +
            "and topology. The key is deliberative practice: not just doing it\n" +
            "again and again, but challenging yourself with a task that is just\n" +
            "beyond your current ability, trying it, analyzing your performance\n" +
            "while and after doing it, and correcting any mistakes. Then repeat.\n" +
            "And repeat again. There appear to be no real shortcuts: even\n" +
            "Mozart, who was a musical prodigy at age 4, took 13 more years\n" +
            "before he began to produce world-class music. In another genre, the\n" +
            "Beatles seemed to burst onto the scene with a string of #1 hits and\n" +
            "an appearance on the Ed Sullivan show in 1964. But they had been\n" +
            "playing small clubs in Liverpool and Hamburg since 1957, and while\n" +
            "they had mass appeal early on, their first great critical success,\n" +
            "Sgt. Peppers, was released in 1967.\n";
    Map<String, Integer> map = countEach(s);
        System.out.println(map.get("great"));
    }

    public Map<String, Integer> countEach(String s) {
        String[] string = s.split("[,. ]");
        Map<String, Integer> map = new HashMap<>();
        for (String e : string) {

            String lowcase = e.toLowerCase();
//            e是字符串进行切割后的一个个单词。
            if (map.containsKey(lowcase)) {
                map.put(lowcase, map.get(lowcase) + 1);
            } else {
                map.put(lowcase, 1);
            }
        }
    return map;
}
}